(custom-set-variables
 ;; custom-set-variables was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 '(ansi-color-names-vector
   ["#212526" "#ff4b4b" "#b4fa70" "#fce94f" "#729fcf" "#e090d7" "#8cc4ff" "#eeeeec"])
 '(async-shell-command-buffer 'new-buffer)
 '(auto-revert-remote-files t)
 '(custom-enabled-themes '(modus-vivendi))
 '(dired-auto-revert-buffer 'dired-directory-changed-p)
 '(dired-recursive-copies 'always)
 '(dired-recursive-deletes 'always)
 '(display-line-numbers-type nil)
 '(ediff-split-window-function 'split-window-horizontally)
 '(eww-search-prefix "https://cn.bing.com/search?q=")
 '(global-auto-revert-mode t)
 '(global-hl-line-mode t)
 '(grep-command "grep --binary-files=without-match --color -nHRs . -e ")
 '(indicate-empty-lines t)
 '(inhibit-startup-screen t)
 '(kill-whole-line t)
 '(make-backup-files nil)
 '(org-confirm-babel-evaluate nil)
 '(package-archives
   '(("gnu" . "https://mirrors.sjtug.sjtu.edu.cn/emacs-elpa/gnu/")
     ("melpa" . "https://mirrors.sjtug.sjtu.edu.cn/emacs-elpa/melpa/")))
 '(package-selected-packages
   '(python-black magit yaml-mode go-mode evil company counsel use-package-ensure-system-package code-cells julia-mode auto-package-update python-mode multi-vterm eshell-vterm use-package ace-window markdown-mode docker-tramp docker dockerfile-mode docker-compose-mode org))
 '(require-final-newline t)
 '(save-place-mode t)
 '(scroll-bar-mode t)
 '(tab-always-indent 'complete)
 '(tramp-default-method "rsync"))

(package-initialize)

;; use package
(if (package-installed-p 'use-package)
    nil
  (progn
    (package-refresh-contents)
    (package-install 'use-package)))
(require 'use-package)
(require 'use-package-ensure)
(setq use-package-always-ensure t)
(use-package use-package-ensure-system-package)
(if (or
     (equal system-configuration "arm-unknown-linux-androideabi")
     (equal system-configuration "aarch64-unknown-linux-android")
     )
    (setq system-packages-use-sudo nil)
  )
;;;
(use-package auto-package-update
  :config
  (setq auto-package-update-delete-old-versions t)
  (setq auto-package-update-hide-results t)
  (auto-package-update-maybe))

(use-package counsel
  :init
  (ivy-mode 1)
  )

(use-package company
  :hook (after-init . global-company-mode)
  )

(use-package evil
  :init
  (evil-mode t)
  )
(use-package eglot)
(use-package project)
(use-package go-mode
  :ensure t
  :requires (eglot project)
  :config
  (cl-defmethod project-root ((project (head go-module)))
    (cdr project))
  (defun project-find-go-module (dir)
    (when-let ((root (locate-dominating-file dir "go.mod")))
      (cons 'go-module root)))
  (add-hook 'project-find-functions #'project-find-go-module)
  (add-hook 'go-mode-hook 'eglot-ensure)
  (add-hook 'before-save-hook #'eglot-format-buffer -10 t))
(use-package yaml-mode)
(use-package julia-mode)
;; (use-package vterm
;;   :if (equal system-configuration "x86_64-unknown-linux-gnu")
;;   :ensure-system-package
;;   ((cmake)
;;    ("/usr/lib/x86_64-linux-gnu/libvterm.so" . libvterm-dev))
;;   )
;; (use-package vterm
;;   :if (or (equal system-configuration "arm-unknown-linux-androideabi") 
;; 	  (equal system-configuration "aarch64-unknown-linux-android")) ;; termux
;;   :ensure-system-package ((cmake)
;;    ((concat (getenv "PREFIX") "/lib/libvterm.so") . libvterm))
;;   :config
;;   (setq vterm-always-compile-module nil)
;;   (setq vterm-clear-scrollback-when-clearing t)
;;   (setq vterm-kill-buffer-on-exit t)
;;   )

;; (use-package julia-snail
;;   :if (eq system-type 'gnu/linux)
;;   ;; :load-path "~/.emacs.d/julia-snail/"
;;   :requires vterm
;;   :hook (julia-mode . julia-snail-mode)
;;   :init
;;   (add-to-list 'display-buffer-alist
;;                '("\\*julia" (display-buffer-reuse-window display-buffer-same-window)))
;;   :init
;;   (setq julia-snail-multimedia-buffer-autoswitch t)
;;   (setq julia-snail-multimedia-enable nil)
;;   (setq julia-snail-multimedia-buffer-style :single-new)
;;   (setq julia-snail-executable "tmux new-session -AE -s snail julia")
;;   )

(use-package code-cells
  :hook (julia-mode . code-cells-mode)
  :bind (:map code-cells-mode-map
	      ("M-p" . code-cells-backward-cell)
	      ("M-n" . code-cells-forward-cell)
	      ("M-RET" . code-cells-eval))
  :config
  (add-to-list 'code-cells-eval-region-commands '(julia-snail-mode . julia-snail-send-code-cell))
  (let ((map code-cells-mode-map))
    (define-key map "n" (code-cells-speed-key 'code-cells-forward-cell))
    (define-key map "p" (code-cells-speed-key 'code-cells-backward-cell))
    (define-key map "e" (code-cells-speed-key 'code-cells-eval))
    (define-key map (kbd "TAB") (code-cells-speed-key (lambda ()
							"Show/hide current cell"
							(interactive)
							(outline-minor-mode)
							(if (outline-invisible-p (line-end-position))
							    (outline-show-subtree)
							  (outline-hide-subtree))))))
  )

(use-package magit
  :config
  (setq magit-diff-refine-hunk t)
  )

(use-package python-black
  :demand t
  :after python
  :hook (python-mode . python-black-on-save-mode-enable-dwim)
  :ensure-system-package
  ((black . "pip install -U black"))
  )

;; enable cmds
(put 'upcase-region 'disabled nil)
(put 'downcase-region 'disabled nil)

;; -diff
(defun command-line-diff (switch)
  (let ((file1 (pop command-line-args-left))
        (file2 (pop command-line-args-left)))
    (ediff file1 file2)))
(add-to-list 'command-switch-alist '("-diff" . command-line-diff))

;; -merge
(defun command-line-merge (switch)
  (let ((base (pop command-line-args-left))
        (sccs (pop command-line-args-left))
        (mine (pop command-line-args-left))
        (merg (pop command-line-args-left)))
    (ediff-merge-with-ancestor sccs mine base () merg)))
(add-to-list 'command-switch-alist '("-merge" . command-line-merge))
;; eof
(custom-set-faces
 ;; custom-set-faces was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 '(default ((t (:family "DejaVu Sans Mono" :foundry "PfEd" :slant normal :weight bold :height 96 :width normal)))))
